package com.hptpd.questionnairesurvey.vo;

import com.google.common.collect.Lists;
import com.hptpd.questionnairesurvey.domain.Dimensionality;
import com.hptpd.questionnairesurvey.domain.UserSurveyScore;
import com.hptpd.questionnairesurvey.utils.AbstractMyBeanUtils;
import lombok.Data;

import java.math.BigDecimal;
import java.util.List;

/**
 * \* Created with IntelliJ IDEA.
 * \* Date: 2019/12/19
 * \*
 * \* Description:
 * \
 *
 * @author walter_long
 */
@Data
public class UserSurveyScoreVo {
    private String id;

    private BigDecimal score;

    private BigDecimal maxScore;

    private BigDecimal hundredMarkScore;

    private BigDecimal hundredMarkMaxScore;

    private DimensionalityVo dimensionalityVo;

    public static List<UserSurveyScoreVo> convertUserSurveyScore(List<UserSurveyScore> userSurveyScores) {
        List<UserSurveyScoreVo> userSurveyScoreVos = Lists.newLinkedList();
        for (UserSurveyScore userSurveyScore : userSurveyScores) {
            userSurveyScoreVos.add(convertUserSurveyScore(userSurveyScore));
        }
        return userSurveyScoreVos;
    }

    public static UserSurveyScoreVo convertUserSurveyScore(UserSurveyScore userSurveyScore) {
        if (null == userSurveyScore) {
            return null;
        }
        UserSurveyScoreVo userSurveyScoreVo = new UserSurveyScoreVo();
        AbstractMyBeanUtils.copyProperties(userSurveyScore, userSurveyScoreVo);
        return userSurveyScoreVo;
    }

    public static BigDecimal getRootScore(Dimensionality dimensionality, BigDecimal score) {
        return getParentDimensionalityScore(dimensionality, score);
    }

    private static BigDecimal getParentDimensionalityScore(Dimensionality dimensionality, BigDecimal score) {
        if (null == dimensionality.getParentDimensionality()) {
            return score;
        }
        BigDecimal weight = new BigDecimal(dimensionality.getWeight());
        return getParentDimensionalityScore(dimensionality.getParentDimensionality(), score.multiply(weight));
    }
}
